OpenBuildings GenerativeComponents Help

Return Value

The return statement is used to indicate what is returned from the function. The type of the return value must be the same as the type of the function. Only one value can be returned from a function, although this can be an array or a multiple array of values. There are other ways to passing more than one value out of a function such as using 'ref' or 'out' values as function arguments. It is possible to create functions which do not return any values; these are known as void functions.

Below are two examples that print the same statement but in different ways. The first has a void output while the second has a string output.

transaction 1 script 'Void Function'
{
    	void showValues(int a, int b)
    	{ 
    		ShowMessageBox("The values selected are " + a + " and " + b + ".");  
    	}
    	int x = 2, y = 4;
    	showValues(x, y);
}

transaction 2 script 'Returning Function'
{
    string showValues(int a, int b)
    {
         return "The values selected are " + ToString(a) + " and " + ToString(b) + ".";
    }
    int x = 2, y = 4;
    ShowMessageBox(showValues(x, y));
}